package edu.gatech.ors.mrsim.core;

import java.util.ArrayList;
import java.util.List;

public class SimFile extends Data<List<FileBlock>> {
	private String name;
	private int blocksize;

	public SimFile(String name, long location, int numBlocks, int blocksize) {
		super(location, 0, new ArrayList<FileBlock>());
		this.size = size;
		for (int s = 0; s < numBlocks; s++) {
			content.add(new FileBlock(s, blocksize));
		}
		this.blocksize = blocksize;
	}

	public long getSize() {
		long totalSize = 0;
		for (Data<Void> data : this.getContent())
			size += data.getSize();
		return totalSize;
	}

	public FileBlock getData(FileBlock data) {
		if (content.contains(data))
			return content.get(content.indexOf(data));
		return null;
	}

	public boolean writeData(FileBlock data) {
		if (!content.contains(data)) {
			content.add(data);
			return true;
		} else {
			int index = content.indexOf(data);
			content.remove(index);
			content.add(index, data);
			return true;
		}
	}

	public int getNumBlocks() {
		return content.size();
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	public boolean equals(Object other) {
		if (!(other instanceof SimFile))
			return false;
		SimFile otherFile = (SimFile) other;
		return name.equals(otherFile.getName());
	}

	/**
	 * @return the blocksize
	 */
	public int getBlocksize() {
		return blocksize;
	}

}
